package com.zhaopin.file;

import com.zhaopin.bean.ParamQueryDetailVO;
import com.zhaopin.bean.ParamVO;
import org.apache.commons.lang3.StringUtils;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @create 2020-01-15 10:57
 */
public class YmlUtilsEasy {

    public static void main(String[] args) throws IOException {
        getParamYaml("E:\\gitrepo\\java-s-gateway\\server\\env\\prodDocker\\prapi\\param-pr-recommend-base.yml");
    }


    public static void getParamYaml(String filePath) throws IOException {
        StringBuilder strq = new StringBuilder();
        StringBuilder strfq = new StringBuilder();

        File file = new File(filePath);
        ParamVO paramVO = new ParamVO();
        Yaml yaml = new Yaml();
        FileInputStream fi = new FileInputStream(file);
        paramVO = yaml.loadAs(fi, ParamVO.class);
        fi.close();

        // 进行数据转化,转化q的数据:
        List<ParamQueryDetailVO> listq = paramVO.getQ();
        if (null != listq) {
            for (int i = 0; i < listq.size(); i++) {
                System.out.println(listq.get(i).getField());

            }
        }
        //进行 fq的数据优化q
        List<ParamQueryDetailVO> listFq = paramVO.getFq();
        for (int i = 0; i < listFq.size(); i++) {
            ParamQueryDetailVO paramQueryDetailVO = listFq.get(i);
            System.out.println(paramQueryDetailVO.getField());

        }

        System.out.println("q:\r\n" + strq.toString());
        System.out.println("----------------------");
        System.out.println("fq:\r\n" + strfq);
    }

}
